import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';
import { PublicService } from '../public.service';
import { SELECT_OPTIONS } from 'app/app.constants';
import { VmsSetComponent } from 'app/public/vms-set/vms-set.component';

@Component({
    selector: 'itmp-vms-modal',
    templateUrl: './Vms-modal.component.html',
    styleUrls: ['./Vms-modal.component.css']
})
export class VmsModalComponent implements OnInit {
    @Input() visible = false;
    @Output() visibleChange = new EventEmitter<boolean>();
    @Input() data: any;
    @ViewChild(VmsSetComponent) vms: VmsSetComponent;
    vmsgetData = {
        illumMode: '0',
        illumLevel: 0,
        illumNumLevels: 0
    };
    illumModeList: Array<any>;
    isOkLoading = false;
    constructor(private pub: PublicService) {}
    ngOnInit() {}
    getData() {}
    close() {
        this.visible = false;
        this.visibleChange.emit(this.visible);
    }
    // 获取改变的vms数据
    commitData(data) {}
    // 初始化数据
    initData(data) {
        this.vmsgetData.illumMode = data && '' + data.illumMode;
        this.vmsgetData.illumLevel = data && data.illumLevel;
        this.vmsgetData.illumNumLevels = data && data.illumNumLevels;
    }
    // cancel 按钮
    handleCancel() {
        this.close();
    }

    // 确定按钮
    handleOk() {
        this.isOkLoading = true;
        this.vms.handleOk(this.vmsgetData).subscribe(res => {
            this.isOkLoading = false;
            if (res === 'success') {
                this.visible = false;
                this.visibleChange.emit(this.visible);
            }
        });
    }
}
